package com.qijia.travel.app;

import com.qijia.travel.common.SqlMappedId;
import com.qijia.travel.dao.BaseDAO;
import com.qijia.travel.dao.SingletonDaoFactory;
import com.qijia.travel.dao.TravelDbException;
import com.qijia.travel.domain.AccLog;

public class AccLogManager {
    public final static String ACC_INSERT_TYPE = "新增:";
    public final static String ACC_UPDATE_TYPE = "修改:";
    public final static String ACC_DELETE_TYPE = "删除:";
    
    public static BaseDAO getBaseDao() throws AppErrorException{
    	try {
			return SingletonDaoFactory.createDAO();
		} catch (TravelDbException e) {
			throw new AppErrorException("操作记录失败! 不能进行操作, 请联系我们的工作人员!");
		}
    }
    
    public static void saveInsertAccLog(Integer guideId, Object obj) throws AppErrorException{
    	AccLog accLog = new AccLog();
    	accLog.setAccGuideId(guideId);
    	accLog.setAccDetail(ACC_INSERT_TYPE+obj.toString());
    	saveAccLog(accLog);
    }
    
    public static void saveUpdateAccLog(Integer guideId, Object obj) throws AppErrorException{
    	AccLog accLog = new AccLog();
    	accLog.setAccGuideId(guideId);
    	accLog.setAccDetail(ACC_UPDATE_TYPE+obj.toString());
    	saveAccLog(accLog);
    }
    
    public static void saveDeleteAccLog(Integer guideId, Object obj) throws AppErrorException{
    	AccLog accLog = new AccLog();
    	accLog.setAccGuideId(guideId);
    	accLog.setAccDetail(ACC_DELETE_TYPE+obj.toString());
    	saveAccLog(accLog);
    }
    
    private static void saveAccLog(AccLog accLog) throws AppErrorException{
    	try {
			getBaseDao().insert(SqlMappedId.ACC_LOG+"."+SqlMappedId.insert, accLog);
		} catch (TravelDbException e) {
			throw new AppErrorException("操作记录失败! 不能进行操作, 请联系我们的工作人员!");
		}
    }
}
